package com.juzipi.framework.security.handler;

import com.juzipi.common.constant.json.ResultCode;
import com.juzipi.common.tools.Result;
import com.juzipi.common.tools.ResultTool;
import com.juzipi.common.utils.json.JsonAuthentication;
import com.juzipi.common.utils.security.SecurityUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未登录
 */

@Component
public class MyAuthenticationEntryPoint extends JsonAuthentication implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        Result result = ResultTool.failCustomize(ResultCode.USER_NOT_LOGIN, null);

        this.WriteJson(httpServletRequest,httpServletResponse,result);
    }
}
